home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!eskimo!scs
- From: scs@eskimo.com (Steve Summit)
- Subject: Re: why arrays may seem like pointers
- X-Nntp-Posting-Host: eskimo.com
- Message-ID: <DnLLD6.6C3@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: schmorganization
- References: <313318b8.53776146@nntp.ix.netcom.com> <DnHyrp.CF8@eskimo.com> <MlB_x9_SMUE45Cwf9Q@transarc.com>
- Date: Fri, 1 Mar 1996 16:48:41 GMT
-
- In article <MlB_x9_SMUE45Cwf9Q@transarc.com>, Jim_Mann@transarc.com writes:
- > scs@eskimo.com (Steve Summit) writes:
- >> I know of at least two reasons why confusion here persists.
- >
- > I think there are serveral others, mostly dealing with common methods
- > of using arrays and pointers... if I declare (and later allocate)
- > char *foo;
- > I can acess elements as foo[3];
-
- Indeed. And this fact suggests that we may be being a bit too
- reactive when we jump all over someone who casually mentions that
- "a pointer is just like an array" or something. Probably all of
- us have written
-
- char *p = malloc(100);
-
- and then treated p as if it were an array; we may say
- (informally) that "p is an array of 100 chars"; and we may even
- use, instead of "p", a name containing the word "array". So when
- someone says "this pointer is an array," in a context where it's
- clear that they mean "this pointer is simulating an array," there
- needn't be any argument. (It is perhaps this misunderstanding
- which has caused some unnecessary debate over in a PL/I vs. C
- thread.)
-
- > For reasons like this, many newer C programmers get to thinking that
- > arrays and pointers are pretty much the same thing.
-
- Yup. And, in some ways, they are, or at least, they can
- certainly seem to act like each other. We should always be
- careful, then, to insert those little extra words: not "this
- pointer is an array" but "this pointer is simulating an array";
- not "an array in a value expression is a pointer" but "an array
- in a value expression generates a pointer."
-
- Steve Summit
- scs@eskimo.com
- --
- The Communications Decency Act within the Telecommunications Act
- of 1996 (U.S.) is an annoying, threatening, abusive, indecent,
- and obscene piece of legislation which attempts to ban annoying,
- threatening, abusive, indecent, or obscene communication.
-